package com.qianclass.talklive.app.json.ImSendMessge;

import com.qianclass.talklive.app.bean.UnLockBean;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;
import com.google.gson.Gson;

import static com.qianclass.talklive.app.activity.VideoActivity.egine;


/**
 * 上、解锁
 * {"message":{"type":"whiteboard","whiteboard":{"subcommand":"lock","status":"false","userid":0}}}
 */

public class SendLockMessage {

    /**
     * @param unlock 是否解锁
     * @param userId
     * @param group
     */
    public static void sendMessge(boolean unlock, int userId, final String group) {
        try {
            UnLockBean unLockBean = new UnLockBean();
            UnLockBean.MessageBean messageBean = new UnLockBean.MessageBean();
            UnLockBean.MessageBean.WhiteboardBean whiteboardBean = new UnLockBean.MessageBean.WhiteboardBean();
            if (unlock) {
                whiteboardBean.setStatus("false");
            }else {
                whiteboardBean.setStatus("true");
            }
            whiteboardBean.setUserid(userId);
            whiteboardBean.setSubcommand("lock");

            messageBean.setWhiteboard(whiteboardBean);
            messageBean.setType("whiteboard");

            unLockBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(unLockBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("解锁" ,jsonString);
        } catch (Exception e){
            LogUtil.i("解锁" , "发送信息失败");
        }

    }
}
